<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


Class TagLibList extends TagLib{
    protected $tags =array(
        "ArticleSort"=>array('attr'=>"id,fid,start,number,where,value,key,order","close"=>1,"level"=>3),
        "Article"=>array('attr'=>"id,fid,start,number,where,value,key,order","close"=>1,"level"=>3),
    );
    
    //查询文章分类
    public function _ArticleSort($attr,$content){
        $tag=  $this->parseXmlAttr($attr, "ArticleSort");
        $start=  empty($tag['start'])?0:$tag['start'];     //起始查询位置
        $number=empty($tag['number'])?"":$tag['number'];   //查询数量
        $key=  empty($tag['key'])?"key":$tag['key'];
        $vo=empty($tag['value'])?"vo":$tag['value'];
        
        
        
        
        $array='$where=array();';
        if(!empty($tag['id'])){
            $array.='$where["article_sort_id"]='.$tag['id'].";";
        }
        
        if(!empty($tag['fid'])){
            $array.='$where["article_sort_parent_id"]='.$tag['fid'].";";
        }
        
        $D="D('ArticleSort')";
        if(intval($number)>0){
            $sql.="->limit('{$start},{$number}')";
        }
        
        if(!empty($tag['order'])){
            $sql.="->order('{$tag['order']}')";
        }
        
        $sql.='->where($where)';
       
        $sql.="->select()";
        $str='<?php '.$array.'$D='.$D.';$rs=$D'.$sql.';';
        $str.='foreach($rs as $'.$key.'=>$'.$vo.'): ?>';
        $str.=$content;
        $str.='<?php endforeach; ?>';
        return $str;
    }
    
    
     //查询文章
    public function _Article($attr,$content){
        $tag=  $this->parseXmlAttr($attr, "Article");
        $start=  empty($tag['start'])?0:$tag['start'];     //起始查询位置
        $number=empty($tag['number'])?"":$tag['number'];   //查询数量
        $key=  empty($tag['key'])?"key":$tag['key'];
        $vo=empty($tag['value'])?"vo":$tag['value'];
        
        
        $array='$where=array();';
        if(!empty($tag['id'])){
            $array.='$where["article_id"]='.$tag['id'].";";
        }
        
        if(!empty($tag['fid'])){
            $array.='$where["article_sort_id"]='.$tag['fid'].";";
        }
        
        $D="D('Article')";
        if(intval($number)>0){
            $sql.="->limit('{$start},{$number}')";
        }
        
        if(!empty($tag['order'])){
            $sql.="->order('{$tag['order']}')";
        }
        
        $sql.='->where($where)';
       
        $sql.="->select()";
        $str='<?php '.$array.'$D='.$D.';$rs=$D'.$sql.';';
        $str.='foreach($rs as $'.$key.'=>$'.$vo.'): ?>';
        $str.=$content;
        $str.='<?php endforeach;?>';
        return $str;
    }
    
    
}



?>
